//
//  WebView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/2.
//

import SwiftUI
import WebKit

struct WebView: View {
    let url: String
    let title: String?
    
    var body: some View {
        VStack {
            // 使用 WebViewRepresentable 加载指定的 URL
            WebViewRepresentable(url: URL(string: url)!)
        }.navigationTitle(title ?? "")
            .background(.bg)
    }
}

struct WebViewRepresentable: UIViewRepresentable {
    var url: URL
    
    func makeUIView(context: Context) -> WKWebView {
        return WKWebView()
    }
    
    func updateUIView(_ uiView: WKWebView, context: Context) {
        let request = URLRequest(url: url)
        uiView.load(request)
    }
}

#Preview {
    WebView(url: "http://cdn.aiyuxm.com/config/privacy/imprint_privacy8.html",title: "网页")
}
